**************************************************************************************************
*** This do file creates the replication results for 
*** Transnational spatial dependencies in the geography of non-resident patent filings  							 	*/
*** Richard Perkins (LSE)																			*/
*** Eric Neumayer (LSE)																			*/
*** Published in: Journal of Economic Geography, 11 (1), 2011, pp. 37-60 														*
**************************************************************************************************
**************************************************************************************************
/* Note: 
You have to change "local DIR" to the directory you copy the original stata files in	 	*/
/* and then run the do file. 													*/
**************************************************************************************************

version 11

***********************************************************************************
local DIR = "C:\Research\Patents\"  /*change relative path to the directory where the files are located */
cd "`DIR'"
***********************************************************************************

use "Article for JEG (patents).dta", clear


** NOTE: You must have listcoef installed. If not, type "findit listcoef" and install.

tsset dyadid year

* Descriptive summary info
quietly xi: reg  patentsfiled  lngdp_reporter lngdp_partner lngdp_pc_partner l.patentsfiled_reporter_byforeign l.patentsfiled_part_abr_notrep  patentrights sameregion_wto sameregion_wb lndistance lndistance_sq   i.year if  reporter!=partner, 
su patentsfiled   l.patfiled_spsource_eps l.patfiled_spsource_reg_wto  lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner   l.patentsfiled_reporter_byforeign l.patentsfiled_part_abr_notrep  patentrights lndistance lndistance_sq sameregion_wto if e(sample)
corr patentsfiled l.patfiled_spsource_eps l.patfiled_spsource_reg_wto  lnexports  lnfdiout    lngdp_partner lngdp_pc_partner  l.patentsfiled_part_abr_notrep   lngdp_reporter  l.patentsfiled_reporter_byforeign patentrights lndistance sameregion_wto if e(sample)

* No SL, no exports, no FDI
xi: nbreg  patentsfiled   lngdp_reporter lngdp_partner lngdp_pc_partner l.patentsfiled_reporter_byforeign l.patentsfiled_part_abr_notrep  patentrights lndistance lndistance_sq    sameregion_wto i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)


* No SL, but exports & FDI
xi: nbreg  patentsfiled lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner  l.patentsfiled_reporter_byforeign  l.patentsfiled_part_abr_notrep patentrights lndistance lndistance_sq    sameregion_wto   i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)
listcoef lnexports  lnfdiout, percent help


* EPS SL
xi: nbreg  patentsfiled lpatfiled_spsource_eps lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner  l.patentsfiled_reporter_byforeign  l.patentsfiled_part_abr_notrep patentrights lndistance lndistance_sq    sameregion_wto   i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)
listcoef lnexports  lnfdiout lpatfiled_spsource_eps , percent help

* Same region SL
xi: nbreg  patentsfiled lpatfiled_spsource_reg_wto lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner  l.patentsfiled_reporter_byforeign  l.patentsfiled_part_abr_notrep patentrights  lndistance lndistance_sq    sameregion_wto  i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)
listcoef lnexports  lnfdiout lpatfiled_spsource_reg_wto , percent help


* Both SLs 
xi: nbreg  patentsfiled  lpatfiled_spsource_eps lpatfiled_spsource_reg_wto lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner   l.patentsfiled_reporter_byforeign l.patentsfiled_part_abr_notrep  patentrights lndistance lndistance_sq    sameregion_wto  i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)
listcoef lnexports  lnfdiout lpatfiled_spsource_eps lpatfiled_spsource_reg_wto, percent help


*** Robustness tests

* Lag 0 of SL
* ALL SL 
xi: nbreg  patentsfiled patfiled_spsource_eps patfiled_spsource_reg_wto lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner   l.patentsfiled_reporter_byforeign l.patentsfiled_part_abr_notrep  patentrights lndistance lndistance_sq   sameregion_wto   i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)

* Lag 2 of SL
* ALL SL 
xi: nbreg  patentsfiled l2.patfiled_spsource_eps l2.patfiled_spsource_reg_wto lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner   l.patentsfiled_reporter_byforeign l.patentsfiled_part_abr_notrep  patentrights lndistance lndistance_sq   sameregion_wto   i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)

* Lag 3 of SL
* ALL SL 
xi: nbreg  patentsfiled l3.patfiled_spsource_eps l3.patfiled_spsource_reg_wto lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner   l.patentsfiled_reporter_byforeign l.patentsfiled_part_abr_notrep  patentrights lndistance lndistance_sq    sameregion_wto  i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)

* Lag 4 of SL
* ALL SL 
xi: nbreg  patentsfiled l4.patfiled_spsource_eps l4.patfiled_spsource_reg_wto lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner   l.patentsfiled_reporter_byforeign l.patentsfiled_part_abr_notrep  patentrights lndistance lndistance_sq    sameregion_wto  i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)

* Lagged dependent variable
xi: nbreg  patentsfiled  l.patentsfiled l.patfiled_spsource_reg_wto l.patfiled_spsource_eps lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner   l.patentsfiled_reporter_byforeign l.patentsfiled_part_abr_notrep  patentrights lndistance lndistance_sq    sameregion_wto  i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)

* Both SLs, World Bank regional classification
xi: nbreg  patentsfiled l.patfiled_spsource_eps l.patfiled_spsource_reg_wb lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner   l.patentsfiled_reporter_byforeign l.patentsfiled_part_abr_notrep  patentrights lndistance lndistance_sq    sameregion_wb  i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)

* Both SLs, patents taken by non-OECD countries only 
xi: nbreg  patentsfiled  l.patfiled_spsource_reg_wto l.patfiled_spsource_eps lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner   l.patentsfiled_reporter_byforeign l.patentsfiled_part_abr_notrep  patentrights lndistance lndistance_sq    sameregion_wto  i.year if  reporter!=partner & inc_highoecd_partner==0, cluster(dyadid) nolrtest iterate(200)

* Patents granted (reg_wto)
xi: nbreg  patentsgranted   l.patgrant_spsource_eps l.patgrant_spsource_reg_wto lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner   l.patentsgranted_rep_byforeign l.patentsgranted_part_abr_notrep  patentrights lndistance lndistance_sq    sameregion_wto  i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)

* Patents granted (reg_wb)
xi: nbreg  patentsgranted   l.patgrant_spsource_eps l.patgrant_spsource_reg_wb lnexports  lnfdiout    lngdp_reporter lngdp_partner lngdp_pc_partner   l.patentsgranted_rep_byforeign l.patentsgranted_part_abr_notrep  patentrights lndistance lndistance_sq    sameregion_wb  i.year if  reporter!=partner, cluster(dyadid) nolrtest iterate(200)


